$url = "http://localhost:5089/api/DefectiveSummary/ExportDefectiveSummary"
$body = @{} | ConvertTo-Json
$headers = @{"Content-Type" = "application/json"}

Write-Host "🧪 测试不良品汇总导出API" -ForegroundColor Green
Write-Host "=" * 50
Write-Host "正在发送请求到: $url" -ForegroundColor Yellow
Write-Host "请求数据: $body" -ForegroundColor Yellow

try {
    $response = Invoke-WebRequest -Uri $url -Method GET -UseBasicParsing
    
    Write-Host "✅ 响应状态码: $($response.StatusCode)" -ForegroundColor Green
    Write-Host "📋 响应头:" -ForegroundColor Yellow
    $response.Headers | Format-Table
    
    if ($response.StatusCode -eq 200) {
        $contentType = $response.Headers.'Content-Type'
        if ($contentType -like "*spreadsheet*") {
            $fileName = "不良品汇总_$(Get-Date -Format 'yyyyMMdd_HHmmss').xlsx"
            [System.IO.File]::WriteAllBytes($fileName, $response.Content)
            Write-Host "📁 Excel文件已保存为: $fileName (大小: $($response.Content.Length) 字节)" -ForegroundColor Green
        } else {
            Write-Host "📄 响应内容:" -ForegroundColor Yellow
            Write-Host $response.Content
        }
    }
} catch {
    Write-Host "❌ 请求失败: $($_.Exception.Message)" -ForegroundColor Red
    if ($_.Exception.Response) {
        Write-Host "状态码: $($_.Exception.Response.StatusCode)" -ForegroundColor Red
        Write-Host "响应内容: $($_.Exception.Response.Content)" -ForegroundColor Red
    }
} 